package com.igeek.boot.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeek.boot.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.Set;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jwj
 * @since 2023-12-26
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from user where username = #{username}")
    @Results({
            @Result(id = true , column = "id" , property = "id"),
            @Result(column = "id" , property = "roles" , javaType = Set.class ,
                    many = @Many(select = "com.igeek.boot.mapper.RoleMapper.findRoleByUserId"))
    })
    User findUserByUsername(String username);

    /**
     * ${ew.customSqlSegment}:拼接where后的语询(在动态sq|中请勿处于标签内)
     * ${ew.sqlSelect} :拼接select SQL主体
     * ${ew.sqlSet} :拼接update主体
     * ${ew.sqlSegment} :拼接where后的语询
     *
     * @param userPage  分页对象
     * @param lambdaQueryWrapper  封装的条件对象
     * @return
     */
    @Select("select * from user ${ew.customSqlSegment}")
    @Results({
            @Result(id = true , column = "id" , property = "id"),
            @Result(column = "id" , property = "roles" , javaType = Set.class ,
                    many = @Many(select = "com.igeek.boot.mapper.RoleMapper.findRoleByUserId"))
    })
    Page<User> selectUserPage(Page<User> userPage, @Param("ew") LambdaQueryWrapper<User> lambdaQueryWrapper);
}
